package net.dgg.rz.common.base;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Description: MyBatis 配置
 * @Author Created by yan.x on 2019-04-30 .
 * @Copyright © HOT SUN group.All Rights Reserved.
 **/
@Configuration
@EnableTransactionManagement
public class DruidDataSourceConfig {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    @Bean
    public ServletRegistrationBean DruidStatViewServle2() {
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        servletRegistrationBean.addInitParameter("loginUsername", "admin");
        servletRegistrationBean.addInitParameter("loginPassword", "admin");
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DruidDataSourceConfig.ServletRegistrationBean 初始化成功!");
        return servletRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean druidStatFilter2() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DruidDataSourceConfig.FilterRegistrationBean 初始化成功!");
        return filterRegistrationBean;
    }
}
